`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    12:56:29 04/30/2014 
// Design Name: 
// Module Name:    KEYBOARD 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module KEYBOARD(
    );


endmodule


always @(negedge k_clk) //Activating at negative edge of clock from keyboard 
			begin 
				case(b) 
					1:; //first bit 
					2:data_curr[0]<=data; 
					3:data_curr[1]<=data; 
					4:data_curr[2]<=data; 
					5:data_curr[3]<=data; 
					6:data_curr[4]<=data; 
					7:data_curr[5]<=data; 
					8:data_curr[6]<=data; 
					9:data_curr[7]<=data; 
					10:flag<=1; //Parity bit 
					11:flag<=0; //Ending bit 
					
					
				endcase 
			if(b<=10) 		
					b<=b+1; 
			else 
					b<=1;			
	end 
	
	

	
	always@(posedge flag)
		begin			
			if (data_past==8'hF0)
					begin		
						case (data_curr)
					8'h1C: left 	<= 0;
					8'h23: right 	<= 0;
					8'h1B: down 	<= 0;
					8'h1D: up 		<= 0;
					8'h29: restart <= 0;
					8'h5A: confirm <= 0;
						endcase												
						
					data_past<=data_curr;
					end
			else 
				begin
					if (data_curr==8'h1C)
						begin
							left <= 1;							
							data_past <= data_curr;
						end				
					else if (data_curr==8'h23)
						begin							
							right <= 1;							
							data_past <= data_curr;					
						end			
					else if (data_curr==8'h1B)
						begin			
							down <= 1;											
							data_past <= data_curr;
						end		
					else if (data_curr==8'h1D)
						begin							
							up <= 1;							
							data_past <= data_curr;
						end				
					else if (data_curr==8'h29)
						begin							
							restart <= 1;
							data_past <= data_curr;
						end				
					 else if (data_curr==8'h5A)
						begin							
							confirm <= 1;
							data_past <= data_curr;
						end
					else if (data_curr==8'h16)
						begin					
							M <=2'b00;	
							data_past <= data_curr;
						end
					else if (data_curr==8'h1E)
						begin					
							M <=2'b01;
							data_past <= data_curr;
						end
					else if (data_curr==8'h26)
						begin					
							M <=2'b10;	
							data_past <= data_curr;
						end
					else if (data_curr==8'h25)
						begin					
							M <=2'b11;	
							data_past <= data_curr;
						end					
					else
						begin 							
							data_past <= data_curr;
						end			
				end

		end		